package com.vdg.fps.ulti;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.auth.BasicScheme;

import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ProxyAuthWebViewClient extends WebViewClient {
	String proxyUserName;
	String proxyPassword;

	public ProxyAuthWebViewClient(String proxyUserName, String proxyPassword) {
		this.proxyUserName = proxyUserName;
		this.proxyPassword = proxyPassword;
	}

	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		loadUrl(view, url, proxyUserName, proxyPassword);
		return true;
	}

	public void loadUrl(WebView view, String url, String proxyUserName,
			String proxyPassword) {
		UsernamePasswordCredentials creds = new UsernamePasswordCredentials(
				proxyUserName, proxyPassword);
		Header credHeader = BasicScheme.authenticate(creds, "UTF-8", true);
		Map<String, String> header = new HashMap<String, String>();
		header.put(credHeader.getName(), credHeader.getValue());
		view.loadUrl(url, header);
	}
}
